<template>
  <div class="login">
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane label="登录" name="first">
        <el-form
          :model="loginForm"
          :rules="rules"
          ref="loginForm"
          label-width="100px"
          class="demo-loginForm"
        >
          <el-form-item label="账号" prop="name" style="width:350px">
            <el-input v-model="loginForm.name" ></el-input>
          </el-form-item>
            <el-form-item label="密码" prop="name" style="width:350px">
            <el-input v-model="loginForm.psw" type="password"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('loginForm')"
              >登录</el-button
            >
            <el-button @click="resetForm('loginForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="注册" name="second">
          <el-form
          :model="registerForm"
          :rules="rules"
          ref="registerForm"
          label-width="100px"
          class="demo-registerForm"
        >
          <el-form-item label="账号" prop="name" style="width:350px">
            <el-input v-model="registerForm.name" ></el-input>
          </el-form-item>
            <el-form-item label="密码" prop="name" style="width:350px">
            <el-input v-model="registerForm.psw" type="password"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('registerForm')"
              >注册</el-button
            >
            <el-button @click="resetForm('registerForm')">重置</el-button>
          </el-form-item>
        </el-form>  
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
import serve from "../util/request";
export default {
  data() {
    return {
      activeName: "first",
      loginForm: {
        name: "",
        psw:""
      },
      registerForm: {
        name:"",
        psw:""
      },
      rules: {
        name: [
          { required: true, message: "请输入", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
    },
    submitForm(formName) {
      this.$refs[formName].validate((val) => {
        if (this.loginForm.name=="13450809860" && this.loginForm.psw=='123') {
          alert("登录成功");
          // this.$router.push("/")
              serve.post("/login", { phone: 13450809860, password: 123 }).then(res=>{
      console.log(res);
    })
        } else if (!val) {
          alert("不能为空");
        } else if(this.loginForm.psw==""){
          alert("密码不能空")
        }
        else{
          alert("账号/密码错误")
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style lang="scss" scoped>
.login {
  margin-top: 80px;
  padding: 100px;
  padding-bottom: 240px;
  background-color: #f4f4f4;
  border-top: 1px solid rgb(224, 224, 224);
}
.el-tabs {
  margin: 0 auto;
  width: 600px  !important;
  background-color: white;
  padding: 30px;
  border-radius: 10px;
  box-shadow: 10px 10px 5px #888888;
}
.el-tabs .el-form-item__content{
  width: 200px !important;
  background-color: black;
}
</style>